package logic

import (
	"context"
	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"
	"doctor-medicine-system/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorDataAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorDataAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorDataAddLogic {
	return &DoctorDataAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 药品信息录入
func (l *DoctorDataAddLogic) DoctorDataAdd(in *doctorrpc.DoctorDataAddRequest) (*doctorrpc.DoctorDataAddResponse, error) {
	// todo: add your logic here and delete this line

	data := mysql.DoctorData{
		Name:    in.Name,
		Size:    in.Size,
		Person:  in.Person,
		Types:   in.Types,
		Number:  in.Number,
		Content: in.Content,
	}
	if err := data.DoctorDataAdd(mysql.DB); err != nil {
		return nil, err
	}

	return &doctorrpc.DoctorDataAddResponse{
		DoctorId: int64(data.ID),
	}, nil
}
